home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Original Shareware 1.1
/
The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso
/
16
/
myed106.zip
/
MYED.BAS
next >
Wrap
BASIC Source File
|
1987-10-15
|
42KB
|
1,414 lines
''''''''''''''''''''''''''''''''''MyEd 1.06''''''''''''''''''''''''''''''''''''
' Copyr. 1986, 1987 Nelson Ford All Rights Reserved
'MyEd is a text editor written in MicroSoft's QuickBasic.
'It has been made as modular as possible so that you can very easily
'customize it to create a stand-alone word processor or incorporate it
'into your own program that might need editing capabilities. Naturally,
'a knowledge of BASIC is required, as is a BASIC compiler.
'A LIMITED LICENSE is hereby granted to individuals, schools and other non-
'profit entities to use all or part of the code in this program file for
'their own private use so long as proper credit and the following information
'is included in your source code:
'COMMERCIAL USE...
'of all or part of this code, including use within a business, or
'ANY DISTRIBUTION of all or part of this code is allowed BY LICENSE ONLY.
'Unlicensed distribution or use of this code is a violation of copyright law
'and subject to civil and criminal prosecution, including substantial fines.
'For licensing information, contact -
' Ford Software, 4845 Willowbend, Houston, TX 77035 713/721-5205
'This file has been heavily annotated and long, descriptive names used for
'variables. Beyond this, we cannot provide support for people using this code
'under the free Limited License (see prior screen). If you wish to register
'for telephone support, send $50 to the address above. If you are new to
'QuickBASIC, you can order a QB Tutorial on disk for $9 from the same author.
'This program uses CALL ABSOLUTE, which requires you to set up and use
'the file USERLIB.EXE. If you do not know how, please read your QB manual
'or call MicroSoft, not Ford Software. USERLIB comes with QB.
'Load this program into QB as follows: QB MYED /L USERLIB.EXE
'The program can be used with StayRes from MicroHelp. This add-on will allow
'you to make the program resident. MicroHelp's phone number is 404-973-9272.
'Programmers who submit significant enhancements to this code or who write
'public domain or shareware programs may be eligible for a free license to
'use this code. Contact Ford Software for more information. We are going
'to continue adding features to this code. Updates will be made available
'and announced through The Public (software) Library and also CompuServe.
DEFINT A-Z
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '
' 'This section of parameters should be modified to define the' '
' 'size and location of the edit area you wish to have: ' '
First.Col = 1 ' '
Last.Col = 80 ' '
First.Row = 1 ' '
Last.Row = 24 ' '
Msg.Line = 25 ' '
Max.Lines =500 ' '
DIM Text$(500), Text.Len(500) ' '
' 'Dimension Text$ and Text.Len to the maximum number of lines' '
' 'Our testing indicates that a maximum of about 500 lines is ' '
' 'possible given BASIC's 64k data segment. ' '
' ' ' '
' 'There are a couple of places where row and column numbers ' '
' 'are hard-coded in. To find these, search for LOCATE. ' '
' ' ' '
' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'============================================================================
10' MAIN PROGRAM LOOP
DIM Locks$(3), On.Off$(1), QPrint.CODE(127), Change$(10)
ON ERROR GOTO Err.Trap
GOSUB Initialize.Parameters
GOSUB Load.File
WHILE NOT the.end.of.the.universe 'loop for a long time
LOCATE Msg.Line,6,0: PRINT Line.Num;
LOCATE Msg.Line,16 : PRINT Char.Num; 'position cursor:
LOCATE First.Row+Line.Num-First.View.Line+1, First.Col+Char.Num-1,1
W$=""
WHILE W$=""
W$=INKEY$ : GOSUB Check.Lock.Status
WEND
IF LEN(W$) = 1_
THEN GOSUB Normal.key.pressed_
ELSE GOSUB Special.key.pressed
IF KY=Alt.X OR W$=Esc$ THEN GOSUB Save.Exit
WEND
'============================================================================
' Main program loop routines:
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Check.Lock.Status:
110'==============
DEF SEG=&H40: New.Status=PEEK(&H17) AND 96: DEF SEG
IF Lock.Status <> New.Status THEN
Addr=VARPTR(QPrint.CODE(0))
x$=Locks$(New.Status/32)
r110=25: c110=73
CALL ABSOLUTE(x$, r110, c110, Attrib, Addr)
Lock.Status = New.Status
IF Lock.Tone > 0 THEN SOUND Lock.Tone+New.Status, Duration!
END IF
RETURN
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Normal.key.pressed:
120'===============
IF W$=Entr$ THEN GOSUB Enter.Pressed_
ELSE IF W$=Bksp$ THEN GOSUB Backspace.Pressed_
ELSE GOSUB AlphaNumeric.Key.Pressed
RETURN
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Special.key.pressed: 'INKEY$ scan code = 2 characters
130'================
KY= ASC(RIGHT$(W$,1))
'cursor keys:
IF KY=RT.Cursor THEN GOSUB Cursor.Right ELSE_
IF KY=LF.Cursor THEN GOSUB Cursor.Left ELSE_
IF KY=UP.Cursor THEN GOSUB Cursor.Up ELSE_
IF KY=DN.Cursor THEN GOSUB Cursor.Dn ELSE_
IF KY=Pg.Up THEN GOSUB Page.Up ELSE_
IF KY=Pg.Dn THEN GOSUB Page.Dn ELSE_
IF KY=Home THEN GOSUB Move.Home ELSE_
IF KY=End.Key THEN GOSUB Move.to.End ELSE_
IF KY=Del.Key THEN GOSUB Del.Char ELSE_
IF KY=Ins.Key THEN GOSUB Toggle.Insert ELSE_
IF KY=Ctrl.RT THEN GOSUB Go.To.Next.Word ELSE_
IF KY=Ctrl.LF THEN GOSUB Go.To.Prev.Word ELSE_
IF KY=Ctrl.End THEN GOSUB Del.to.EOL ELSE_
IF KY=Ctrl.PgUp THEN GOSUB Go.To.File.Bgn ELSE_
IF KY=Ctrl.PgDn THEN GOSUB Go.To.File.End ELSE_
_' special functions:
IF KY=Alt.B THEN GOSUB Define.Block ELSE_
IF KY=Alt.E THEN GOSUB Erase.Block ELSE_
IF KY=Alt.P THEN GOSUB Paste.Block ELSE_
IF KY=Alt.U THEN GOSUB Unmark.Block ELSE_
IF KY=Alt.D THEN GOSUB Del.Line ELSE_
IF KY=Alt.R THEN GOSUB Reform ELSE_
IF KY=Alt.I THEN GOSUB Toggle.Indent ELSE_
IF KY=Alt.W THEN Wrap.On = Not Wrap.On ELSE_
IF KY=Alt.F THEN GOSUB Find.Text ELSE_
IF KY=Alt.C THEN GOSUB Clear.Lines ELSE_
IF KY=Alt.N THEN GOSUB New.File ELSE_
IF KY=Alt.M THEN GOSUB Set.Rt.Margin ELSE_
IF KY=Alt.H THEN GOSUB Help.Screen ELSE_
IF KY=Alt.G THEN GOSUB Get.more.file ELSE_
IF KY=Alt.K THEN GOSUB Toggle.Auto.Cap
RETURN
'''''''''''''''''''''''''end of main loop routines''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' "Normal Key Pressed" routines:
'AlphaNumeric.Key.Pressed .. Add the keypress (W$) to the line of text.
'Enter.Pressed ............. Process Enter keypress.
'Backspace.Pressed ......... Process Backspace keypress.
AlphaNumeric.Key.Pressed:
1210'====================
IF Auto.Cap THEN GOSUB Cap.First.Letter
IF Insert THEN 'If Insert mode is on then
IF Char.Num < Max.Text.Len THEN 'if there is room then
IF Text.Len(Line.Num) = Max.Text.Len-1 THEN 'if this is end of the line
IF Wrap.On THEN 'the if wrap is on, go move
GOSUB Wrap 'the last word on the line
ELSEIF EEK>0 THEN 'otherwise, make a noise to
SOUND EEK,EEK! 'indicate the end of line
RETURN 'and return.
END IF 'Note that in the Insert mode, the cusor is not necessarily
END IF 'at the end of the line when you run out of room above.
'Now that there is room, insert the character:
MID$(Text$(Line.Num),Char.Num) = W$ + MID$(Text$(Line.Num),Char.Num)
Char.Num=Char.Num+1
Text.Len(Line.Num)=Text.Len(Line.Num)+1
GOSUB Prnt
RETURN
END IF
END IF
'Insert is not on, so overtype:
MID$(Text$(Line.Num),Char.Num,1)=W$
Char.Num=Char.Num+1
PRINT W$;
IF Char.Num > Text.Len(Line.Num) THEN_
Text.Len(Line.Num) = Char.Num-1
IF Char.Num > Max.Text.Len THEN
IF Wrap.On THEN GOSUB Wrap
IF Char.Num > Max.Text.Len THEN
Char.Num = Max.Text.Len
IF EEK>0 THEN SOUND EEK,EEK!
END IF
END IF
RETURN
''''''
Enter.Pressed:
1220'=========
IF Line.Num < Max.Lines THEN ' if this is not the last line then
IF Insert_ ' if Insert is on
AND Last.Line < Max.Lines THEN_ ' and there is still room
GOSUB Split.Line ' then split the line at the
IF Indent.On THEN_ ' cursor point.
GOSUB Find.Indent
Line.Num=Line.Num+1 ' increment line pointer
Char.Num=Indent+1 ' move character pointer to start.
IF Line.Num > Last.Line THEN_ ' increment Last.Line count
Last.Line=Line.Num ' if necessary.
IF Line.Num > Last.View.Line THEN_
GOSUB Scroll.Up
END IF
GOSUB Prnt
RETURN
Backspace.Pressed:
1230'=============
'backspace key deletes the character at the cursor
IF Char.Num>1 THEN ' and moves the following text left 1 space, adding
Char.Num=Char.Num-1 ' a space at the end to keep the line length right.
Text$(Line.Num)=LEFT$(Text$(Line.Num),Char.Num-1)_
+MID$(Text$(Line.Num),Char.Num+1)+" "
Text.Len(Line.Num)=Text.Len(Line.Num)-1
Char.Num=Char.Num-1
END IF
GOSUB Prnt
''''''''''''''''''''end of main "Normal Key Pressed" Routines''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' "Special Key Pressed" Routines:
Cursor.Right:
1310'========
IF Char.Num < Max.Text.Len_
THEN Char.Num = Char.Num + 1
RETURN
Cursor.Left:
1320'=======
IF Char.Num > 1 THEN_
Char.Num = Char.Num - 1
RETURN
Cursor.Up:
1330'=====
GOSUB Find.Text.Len
IF Line.Num > 1 THEN
IF Line.Num = First.View.Line THEN
GOSUB Scroll.down
END IF
IF Line.Num > Last.Line_
AND Text.Len(Line.Num) <> 0 THEN
Last.Line = Line.Num
END IF
Line.Num = Line.Num - 1
ELSE IF EEK>0 THEN SOUND EEK,EEK!
END IF
RETURN
Scroll.Down:
1331'-------
First.View.Line = First.View.Line - 1
Last.View.Line = Last.View.Line - 1
current.line = Line.Num
FOR Line.Num = First.View.Line TO Last.View.Line
GOSUB Prnt
NEXT
Line.Num = current.line
RETURN
Cursor.Dn:
1340'=====
GOSUB Find.Text.Len
IF Line.Num < Max.Lines THEN
IF Line.Num = Last.View.Line THEN_
GOSUB Scroll.Up
IF Line.Num > Last.Line_
AND Text.Len(Line.Num) <> 0 THEN_
Last.Line = Line.Num
Line.Num = Line.Num + 1
ELSE IF EEK>0 THEN SOUND EEK,EEK!
END IF
RETURN
Page.Up:
1350'===
IF First.View.Line - Num.View.Lines => 1 THEN
First.View.Line = First.View.Line - Num.View.Lines
Line.Num = Line.Num - Num.View.Lines
Last.View.Line = Last.View.Line - Num.View.Lines
ELSE First.View.Line = 1
Line.Num = 1
Last.View.Line = Num.View.Lines
IF EEK>0 THEN SOUND EEK,EEK!
END IF
GOSUB Prnt.Lines
RETURN
Page.Dn:
1360'===
IF Last.View.Line + Num.View.Lines <= Max.Lines THEN
Last.View.Line = Last.View.Line + Num.View.Lines
Line.Num = Line.Num + Num.View.Lines
First.View.Line = First.View.Line + Num.View.Lines
ELSE First.View.Line = Max.Lines - Num.View.Lines + 1
Last.View.Line = Max.Lines
Line.Num = Last.View.Line
IF EEK>0 THEN SOUND EEK,EEK!
END IF
GOSUB Prnt.Lines
RETURN
Move.Home:
1370'=====
IF Indent.On THEN_
GOSUB Find.Indent
IF Char.Num > Indent+1_
THEN Char.Num=Indent+1_
ELSE Char.Num=1
RETURN
Move.to.End:
1380'=======
IF Text.Len(Line.Num) < Max.Text.Len_
THEN Char.Num = Text.Len(Line.Num) + 1_
ELSE Char.Num = Text.Len(Line.Num)
RETURN
Del.Char:
1390'====
IF Char.Num <= Text.Len(Line.Num) THEN
MID$(Text$(Line.Num), Char.Num)= _
MID$(Text$(Line.Num), Char.Num+1)+" "
Text.Len(Line.Num)=Text.Len(Line.Num)-1
GOSUB Prnt
ELSE dc.ln=Line.Num
GOSUB reform
Line.Num=dc.ln
END IF
RETURN
Toggle.Insert:
1400'=========
IF Insert=NO_
THEN Insert=Yes:_
Locate ,,1,CU1,CU2_ 'change to a half-block cursor shape
ELSE Insert=NO:_
Locate ,,,CU2 'change to an underline cursor shape
RETURN
Go.To.Next.Word:
1410'===========
IF Char.Num < Text.Len(Line.Num) + 1 THEN_
Char.Num = Char.Num + 1:_
WHILE Char.Num<Text.Len(Line.Num)+1_
AND Char.Num<Max.Text.Len_
AND (MID$(Text$(Line.Num),Char.Num-1,1)<>" "_
OR MID$(Text$(Line.Num),Char.Num-1,2)=" "):_
Char.Num=Char.Num-(Char.Num<Max.Text.Len):_
WEND
RETURN
Go.To.Prev.Word:
1420'===========
IF Char.Num> 2 THEN
Char.Num=Char.Num-1
WHILE Char.Num >2_
AND ( MID$(Text$(Line.Num),Char.Num-1,1)<>" "_
OR MID$(Text$(Line.Num),Char.Num-1,2) =" " )
IF Char.Num > 2 THEN
Char.Num = Char.Num - 1
END IF
WEND
IF Char.Num = 2_
AND MID$(Text$(Line.Num),Char.Num, 1) <> " " THEN_
Char.Num=1
ELSE Char.Num=1
END IF
RETURN
Del.to.EOL: 'delete from the cursor position to the end of the line
1430'======
Text$(Line.Num)=LEFT$(Text$(Line.Num), Char.Num - 1)_
+SPACE$(Max.Text.Len - Char.Num + 1)
Text.Len(Line.Num)=Char.Num-1
GOSUB Prnt
RETURN
Go.To.File.Bgn:
1440'==========
IF First.View.Line=1 THEN IF EEK>0 THEN SOUND EEK,EEK!
First.View.Line=1
Last.View.Line = First.View.Line + Num.View.Lines -1
GOSUB Prnt.Lines
Line.Num=1
RETURN
Go.To.File.End:
1450'==========
IF Last.View.Line=Last.Line THEN IF EEK>0 THEN SOUND EEK,EEK!
Last.View.Line=Last.line
First.View.Line = Last.View.Line - Num.View.Lines + 1
GOSUB Prnt.Lines
Line.Num=Last.View.Line
RETURN
Define.Block:
1460'========
IF Line.Num > Block.Start_
AND Block.Start > 0_
THEN Block.End = Line.Num_
ELSE Block.Start = Line.Num:_
IF Block.End=0_
THEN Block.End = Block.Start
remember=Line.Num
IF Line.Num < First.View.Line_
THEN Line.Num = First.View.Line_
ELSE Line.Num = Block.Start
IF Block.End > Last.View.Line_
THEN b.e=Last.View.Line_
ELSE b.e=Block.End
WHILE Line.Num <= b.e
Gosub Prnt
Line.Num=Line.Num+1
WEND
Line.Num=remember
RETURN
Erase.Block:
1470'=======
IF Block.Start=0 THEN RETURN
block = Block.End - Block.Start + 1
Last.Line = Last.Line - Block
FOR l = Block.Start TO Last.Line
Text$(l) = Text$(l+block)
Text.Len(l) = Text.Len(l+block)
NEXT
FOR l=Last.Line+1 TO Last.Line+block
Text$(l) = SPACE$(Max.Text.Len)
Text.Len(l) = 0
NEXT
'The purpose of this next section of code is to try to keep the cursor on the
'line it's on after deleting the lines in the block and to keep the cursor
'line from moving.
IF Block.Start => First.View.Line_
AND Block.Start <= Last.View.Line THEN
IF Line.Num > Block.Start THEN_
IF Line.Num <= Block.End_
THEN Line.Num = Block.Start_
ELSE Line.Num = Line.Num - block:_
IF First.View.Line - block > 0 THEN_
First.View.Line = First.View.Line - block:_
Last.View.Line = First.View.Line + Num.View.Lines -1
ELSEIF Block.End <= Last.View.Line THEN
Line.Num = Line.Num - block
First.View.Line = First.View.Line - block
Last.View.Line = First.View.Line + Num.View.Lines -1
END IF
GOSUB Unmark.Block
RETURN
Paste.Block:
1480'=======
IF Block.Start = 0 THEN RETURN
block = Block.End - Block.Start + 1
IF Last.Line + block > Max.Lines THEN
Locate Msg.Line,25: PRINT SPACE$(45);: LOCATE Msg.Line,25: COLOR HL
PRINT "Not enough space left.";: COLOR FG
xxx$="": WHILE xxx$="": xxx$=INKEY$: WEND
LOCATE Msg.Line,25: PRINT SPACE$(40);
RETURN
END IF
FOR x=Last.Line+block TO Line.Num+block STEP -1
Text$(x) = Text$(x-block)
Text.Len(x) = Text.Len(x-block)
NEXT
FOR x=Line.Num TO Line.Num+block-1
Text$(x) = Text$(Block.Start + x-Line.Num)
Text.Len(x) = Text.Len(Block.Start + x-Line.Num)
NEXT
Last.Line = Last.Line + block
GOSUB Prnt.Lines
RETURN
Unmark.Block:
1490'========
Block.Start=0
Block.End=0
GOSUB Prnt.Lines
RETURN
Del.Line:
1500'====
I=Line.Num
FOR Line.Num=I TO Last.Line
Text$(Line.Num)=Text$(Line.Num+1)
Text.Len(Line.Num)=Text.Len(Line.Num+1)
IF Line.Num <= Last.View.Line THEN_
GOSUB Prnt
NEXT
Line.Num=I
Last.Line=Last.Line-1
RETURN
Toggle.Indent:
'=============
IF Indent.On = Yes_
THEN Indent.On = No:_
Indent = 0_
ELSE Indent.On = Yes
RETURN
Find.Text:
1520'=====
LOCATE Msg.Line,22: PRINT SPACE$(45);:
LOCATE Msg.Line,22: COLOR HL
PRINT "Text to find: ";: COLOR FG: col=POS(0)
GOSUB Get.input
srch$=LEFT$(Text$(0), Text.Len(0))
IF W$=Esc$ THEN LOCATE,22: PRINT SPACE$(45): RETURN
l=Line.Num+1
1521'
WHILE l <> Line.Num_
AND INSTR(Text$(l), srch$)=0
l=l+1
IF l > Last.Line THEN l=1
WEND
LOCATE Msg.Line,22: PRINT SPACE$(45);
1522'
IF Line.Num <> l_
THEN
Line.Num=l
IF l > Last.View.Line_
OR l < First.View.Line THEN
IF Line.Num > (Num.View.Lines\2)_
THEN First.View.Line=Line.Num - Num.View.Lines\2_
ELSE First.View.Line=1
Last.View.Line=First.View.Line + Num.View.Lines - 1
GOSUB Prnt.Lines
END IF
Char.Num=Instr(Text$(l), srch$)
Locate First.Row+Line.Num-First.View.Line+1, First.Col+Char.Num-1,1
COLOR HL: PRINT srch$;: COLOR FG
ELSE
LOCATE Msg.Line,22: PRINT Srch$ " NOT FOUND.";
x$="": WHILE x$="": x$=INKEY$: WEND
LOCATE Msg.Line,22: PRINT SPACE$(45);
END IF
RETURN
Clear.Lines:
'===========
LOCATE Msg.Line,25: PRINT SPACE$(45);: LOCATE Msg.Line,25
COLOR HL
PRINT "Confirm: Clear all lines (y/n)";
COLOR FG
x$="": WHILE x$="": x$=INKEY$: WEND
LOCATE Msg.Line,25: PRINT SPACE$(45);
IF x$="y" OR x$="Y" THEN GOSUB Clear.mem: Fi$="": GOSUB Prnt.Lines
RETURN
Clear.mem:
'---------
FOR x=1 TO Max.Lines
Text$(x)=SPACE$(Max.Text.Len)
Text.Len(x)=0
NEXT
Line.Num=1
Char.Num=1
First.View.Line=1
Last.View.Lines=Num.View.Lines
Last.Line=0
RETURN
New.File:
'========
LOCATE Msg.Line,25: PRINT SPACE$(45);
LOCATE Msg.Line,25: COLOR HL
PRINT "Confirm: Load new file (y/n)";
COLOR FG
x$="": WHILE x$="": x$=INKEY$: WEND
LOCATE Msg.Line,25: PRINT SPACE$(45);
IF x$="y" OR x$="Y" THEN
FOR x=1 TO Max.Lines
Text$(x)=SPACE$(Max.Text.Len)
Text.Len(x)=0
NEXT
GOSUB Load.File
END IF
RETURN
Set.Rt.Margin:
'=============
LOCATE Msg.Line,25: PRINT SPACE$(45);: LOCATE ,25
'PRINT "Enter new right margin: ";
PRINT "Feature not implemented yet.";
'Last.Col=0
'WHILE (Last.Col < First.Col) or (Last.Col > 80)
'Locate Msg.Line,48
LINE INPUT; x$
'Last.Col=val(x$)
'WEND
LOCATE ,25: PRINT SPACE$(45);
'Max.Text.Len=Last.Col-First.Col+1
RETURN
Get.more.file:
'=============
IF Next.section=0 THEN RETURN
IF End.of.big.file THEN
LOCATE Msg.Line,25: PRINT SPACE$(45);: LOCATE ,25
COLOR HL: PRINT "* * * END OF FILE * * *";
w$="": WHILE w$="": w$=INKEY$: WEND
LOCATE Msg.Line,25: PRINT SPACE$(45);: LOCATE ,25
RETURN
END IF
LOCATE Msg.Line,25: PRINT SPACE$(45);: LOCATE ,25
COLOR HL: PRINT "* GETTING NEXT SECTION *";
GOSUB Save.it
GOSUB Clear.Mem
1801'
OPEN Fi$ FOR INPUT AS #1
FOR x = 1 TO Next.section
LINE INPUT #1, A$
NEXT
GOSUB Read.in.text
First.View.Line=1
Last.View.Line=Num.View.Lines
Current.Line=1
GOSUB Prnt.lines
RETURN
Toggle.Auto.Cap:
'===============
'The following routine toggles Auto.cap & changes the Auto.cap status display.
' (Auto.cap capitalizes the first letter of each word.)
Auto.Cap=NOT Auto.Cap:_
LOCATE Msg.Line,69
COLOR HL
Print On.Off$(1+Auto.Cap);
COLOR FG
IF EEK>0 THEN SOUND EEK,EEK!
RETURN
Cap.First.Letter:
'================
IF Char.Num > 1 THEN_
IF INSTR(Delimiter$, MID$(Text$(Line.Num),Char.Num-1,1)) > 0 THEN_
IF W$>="a" AND W$<="z" THEN_
W$=CHR$(ASC(W$)-32)
RETURN
Wrap:
'====
IF Line.Num=Max.Lines THEN
LOCATE Msg.Line,28: COLOR HL
PRINT "No more lines allowed. Press C.";
IF EEK>0 THEN SOUND EEK,EEK!
xxx$="" : WHILE xxx$<>"C" AND xxx$<>"c" : xxx$=INKEY$: WEND
LOCATE Msg.Line,28: COLOR FG
PRINT SPACE$(40);
Char.Num=Char.Num-1
Last.Line=Max.Lines
RETURN
END IF
IF Insert THEN_
IF Char.Num < Text.Len(Line.Num)+1_
THEN GOTO Insert.Wrap_
ELSE IF Line.Num < Last.Line_
THEN GOSUB Move.lines.down
IF W$=" " THEN_
GOSUB Find.text.len:_
Split.point=Max.Text.Len:_
GOTO Incr.pointers
Split.Point = Max.Text.Len - 1
WHILE MID$(Text$(Line.Num), Split.Point ,1) <> " " AND Split.Point > 2
Split.Point = Split.Point - 1
WEND
IF Indent.On THEN
GOSUB Find.Indent
END IF
IF Split.Point = Indent THEN_
Split.Point = Max.Text.Len - 1
IF Split.Point > 1 THEN
MID$(Text$(Line.Num+1),Indent+1) = MID$(Text$(Line.Num),Split.Point+1)
MID$(Text$(Line.Num),Split.Point+1) = SPACE$(Max.Text.Len-Split.Point)
GOSUB Prnt
GOSUB Find.Text.Len
END IF
Incr.pointers:
Line.Num=Line.Num+1
GOSUB Find.Text.Len
IF Insert_
THEN Char.Num=Text.Len(Line.Num)+1:_
Last.Line=Last.Line+1_
ELSE Char.Num=Indent+Max.Text.Len-Split.Point+1
IF Line.Num > Last.Line THEN Last.Line=Line.Num
IF Line.Num > Last.View.Line THEN
GOSUB Scroll.Up
END IF
GOSUB Prnt
RETURN
Insert.Wrap:
'----------
Original.char.pos = Char.Num
Char.Num = Char.Num + 1
WHILE MID$(Text$(Line.Num), Char.Num, 1)<>" "_
AND Char.Num < Max.Text.Len
Char.Num = Char.Num + 1
WEND
IF Char.Num = Max.Text.Len THEN Char.Num = Original.char.pos + 1
GOSUB Split.line
Char.Num= Original.char.pos
RETURN
Move.lines.down:
'===============
Current.Line = Line.Num
FOR Line.Num = Last.Line+1 TO Current.Line+2 STEP -1
Text$(Line.Num) = Text$(Line.Num-1)
Text.Len(Line.Num) = Text.Len(Line.Num-1)
IF Line.Num <= Last.View.Line THEN
GOSUB Prnt
END IF
NEXT
Line.Num = Current.Line
Text$(Line.Num+1) = SPACE$(Max.Text.Len)
Text.Len(Line.Num+1) = 0
Last.Line = Last.Line + 1
RETURN
'''''''''''''''''end of "AlphaNumeric Key Pressed" subroutines'''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
2000' General Program Subroutines:
'Prnt ................... Assm. subroutine to print a line of text quickly.
'Prnt.Lines ............. Print all the text lines on the screen.
'Find.Text.Len .......... Finds last character in the line of text.
'Find.Indent ............ Starts new line at same first char. as prior line.
'Scroll.Up .............. Scroll lines up on the screen.
'Split.Line ............. Divide a line at the cursor position.
'Reform ................. Reform a paragraph from the cursor line.
2010'
Prnt:
'====
IF Line.Num > Last.View.Line THEN GOSUB Scroll.Up
DEF SEG
addr=VARPTR(QPrint.CODE(0))
prnt.txt$ = Text$(Line.Num)
IF Line.Num=0 THEN
row = csrlin
CALL ABSOLUTE(Text$(0), row, Col, Attrib, addr)
RETURN
END IF
prnt.row = First.Row + Line.Num - First.View.Line + 1
IF Block.Start > 0 THEN
IF Line.Num => Block.Start_
AND Line.Num <= Block.End_
AND Attrib=FG.BG_
THEN Attrib=BG.FG
END IF
CALL ABSOLUTE(prnt.txt$, prnt.row, First.Col, Attrib, addr)
Attrib=FG.BG
RETURN
2020'
Prnt.Lines:
'==========
current.line=Line.Num
FOR Line.Num = First.View.Line TO Last.View.Line
GOSUB Prnt
NEXT
Line.Num=current.line
COLOR HL,BG: LOCATE Msg.Line,1
PRINT "LINE: CHAR: Editing " Fi$". Alt-H for Help.";_
SPACE$(80-POS(0));
COLOR FG,BG
RETURN
2030'
Find.text.len: 'sets Text.Len to last non-blank character in a line
'=============
Text.Len(Line.Num)=Max.Text.Len
WHILE MID$(Text$(Line.Num), Text.Len(Line.Num), 1) = " "_
AND Text.Len(Line.Num) > 1
Text.Len(Line.Num) = Text.Len(Line.Num) - 1
WEND
IF Text.Len(Line.Num)=1_
AND LEFT$(Text$(Line.Num),1)=" "_
THEN Text.Len(Line.Num)=0
RETURN
2040'
Find.Indent: 'for auto-indent: starts new line at same cursor position
'=========== ' as the preceeding line.
Indent=0
IF Text$(Line.Num) <> SPACE$(Max.Text.Len) THEN
WHILE Indent+1 < Max.Text.Len_
AND MID$( Text$(Line.Num), Indent+1, 1 ) = " "
Indent = Indent + 1
WEND
END IF
RETURN
2050'
Scroll.Up:
'=========
First.View.Line = First.View.Line + 1
Last.View.Line = Last.View.Line + 1
current.line = Line.Num
FOR Line.Num = First.View.Line TO Last.View.Line
GOSUB Prnt
NEXT
Line.Num = current.line
RETURN
2060'
Split.line:
'==========
GOSUB Move.lines.down
IF Indent.On THEN GOSUB Find.Indent
Line.Num = Line.Num + 1
MID$(Text$(Line.Num), Indent+1) = MID$(Text$(Line.Num-1), Char.Num)
GOSUB Find.text.len
IF Line.Num > Last.View.Line THEN
GOSUB Scroll.Up
END IF
GOSUB Prnt
'Remove split-off text from current line:
Line.Num=Line.Num-1
MID$(Text$(Line.Num), Char.Num) = SPACE$(Max.Text.Len)
GOSUB Find.text.len
GOSUB Prnt
RETURN
2070'
Reform: 'to reform a paragraph from the cursor line to the end of para.
'======
IF Text$(Line.Num) = SPACE$(Max.Text.Len) THEN RETURN
'find the end of the paragraph:
IF Indent.On THEN GOSUB Find.Indent
End.of.Para=Line.Num
WHILE MID$(Text$(End.of.Para+1), Indent+1, 3) <> " "_
AND End.of.Para < Last.Line
End.of.Para = End.of.Para + 1
WEND
IF Line.Num=End.of.Para THEN RETURN
IF KY=Del.Key THEN End.of.Para=Line.Num+1: KY=0
Remember.line.num=Line.Num
Blanks=0
WHILE Line.Num < End.of.Para
Next.Line=Line.Num+1
IF Indent.On THEN
Line.Num=Next.Line
GOSUB Find.Indent
Line.Num=Next.Line-1
END IF
'Combine two lines if possible:
WHILE (Text.Len(Line.Num) + Text.Len(Next.Line) - Indent) < Max.Text.Len_
AND Next.Line <= End.of.Para
MID$(Text$(Line.Num), Text.Len(Line.Num)+2)_
=MID$(Text$(Next.Line), Indent+1, Text.Len(Next.Line)-Indent)
Text.Len(Line.Num) = Text.Len(Line.Num) + Text.Len(Next.Line)-Indent + 1
Next.Line = Next.Line + 1
WEND
IF Next.Line > Line.Num+1 THEN
Move.up=Next.Line - Line.Num -1
FOR x=Line.Num+1 to End.of.Para-Move.up
Text$(x)=Text$(x+Move.up)
Text.Len(x)=Text.Len(x+Move.up)
NEXT
FOR x=End.of.Para-Move.up+1 to End.of.Para
Text$(x)=SPACE$(Max.Text.Len)
Text.Len(x)=0
NEXT
End.of.Para=End.of.Para-Move.up
Blanks=Blanks+Move.up
Next.Line=Line.Num+1
END IF
'find next word in next line and move it up to the current line:
IF Next.Line <= End.of.Para THEN
Next.Word = INSTR(Indent+2,Text$(Next.Line)," ")-1
IF Text.Len(Line.Num) +1 + Next.Word-Indent <= Max.Text.Len_
AND Next.Word > 0 THEN
WHILE INSTR(Next.Word+2, Text$(Next.Line), " ") > 0_
AND INSTR(Next.Word+2, Text$(Next.Line), " ")-1 < Text.Len(Next.Line)_
AND INSTR(Next.Word+2, Text$(Next.Line), " ")-Indent_
+ Text.Len(Line.Num)_
<= Max.Text.Len
Next.Word = INSTR(Next.Word+2, Text$(Next.Line), " ")-1
WEND
'move word up from next line:
MID$(Text$(Line.Num), Text.Len(Line.Num)+2) = _
MID$(Text$(Next.Line), Indent+1, Next.Word-Indent)
Text.Len(Line.Num)= Text.Len(Line.Num) + Next.Word-Indent + 1
MID$(Text$(Next.Line), Indent+1) = MID$(Text$(Next.Line), Next.Word+2)_
+ SPACE$(Next.Word+1-Indent)
Text.Len(Next.Line)=Text.Len(Next.Line)-(Next.Word+1-Indent)
END IF
END IF
GOSUB Prnt
Line.Num=Line.Num+1
WEND
GOSUB Prnt
'Move up rest of lines in the file:
IF End.of.Para <> Last.Line THEN
IF End.of.Para + Blanks <> Last.Line THEN
FOR Line.Num = End.of.Para+1 TO Last.Line-Blanks
Text$(Line.Num)=Text$(Line.Num+Blanks)
Text.Len(Line.Num)=Text.Len(Line.Num+Blanks)
IF Line.Num <= Last.View.Line THEN
GOSUB Prnt
END IF
NEXT
END IF
FOR Line.Num = Last.Line-Blanks+1 to Last.Line
Text$(Line.Num)=SPACE$(Max.Text.Len)
Text.Len(Line.Num)=0
IF Line.Num <= Last.View.Line THEN
GOSUB Prnt
END IF
NEXT
END IF
Line.Num=End.of.Para
Last.Line=Last.Line-Blanks
IF Line.Num+1 < Max.Lines THEN Line.Num=Line.Num+1
RETURN
2080'
Get.input:
'=========
l2080=Line.Num: Line.Num=0
r2080=CSRLIN: c2080=POS(0)
Text$(0)=space$(Max.Text.Len): W$="": Char.Num=1
Text.Len(0)=0
WHILE W$<>Entr$
IF LEN(W$) = 1 THEN GOSUB Normal.key.pressed
W$=""
LOCATE r2080,c2080+Char.num-1
WHILE W$=""
W$=INKEY$ : GOSUB Check.Lock.Status
WEND
WEND
Line.Num=l2080
IF Text$(0)=SPACE$(Max.Text.Len) THEN Text$(0)=""
RETURN
'------------------------end of main loop subroutines-----------------------
'-------------------------------help screen----------------------------------
3000'
Help.Screen:
l=First.Row+1: h$=""
RESTORE help.data
read h$
WHILE h$<>"done"
DEF SEG: Addr=VARPTR(QPrint.CODE(0))
x$=SPACE$(Max.Text.Len)
FOR n=First.Row+1 TO Last.Row
CALL ABSOLUTE(x$, n, First.Col, Attrib, Addr)
NEXT
WHILE l < Last.Row AND h$<>"done"
x$=SPACE$(Max.Text.Len) 'this line and the next either cuts the line
MID$(x$,1)=h$ 'down or pads with blanks to fit the available space.
DEF SEG
Addr=VARPTR(QPrint.CODE(0))
CALL ABSOLUTE(x$, l, First.Col, Attrib, Addr)
l=l+1
READ h$
WEND
xxx$="": while xxx$="": xxx$=inkey$: wend
l=First.Row+1
WEND
GOSUB Prnt.Lines
RETURN
help.data:
data "Alt-B defines the beginning/end of a block of lines."
data "Alt-C clears all lines."
data "Alt-D deletes the line at the cursor position."
data "Alt-E erases a block of lines."
data "Alt-F finds specified text"
data "Alt-G gets next section of a large file."
data "Alt-I toggles auto-indent."
data "Alt-K automatically caps the first letter of each word."
data "Alt-M set right Margin."
data "Alt-N to load a new file."
data "Alt-P pastes (copies) a block of lines."
data "Alt-R reforms paragraph from the current line down."
data "Alt-U unmarks a block of lines."
data "Alt-W toggles word-wrap on/off."
data "Alt-X save and exit."
data "Esc exit without saving."
data "Ctrl-End deletes from the cursor to the end of the line."
data "Ins toggles Insert mode."
data "ENTER pressed in the Insert mode splits a line at the cursor position."
data "Del at end of text joins two lines."
data "Cursor movement keys:"
data " Up, Down, Left, Right."
data " Home, End - Move to start or end of text. Again: start/end of line."
data " Ctrl-Left Ctrl-Right - move cursor 1 word left or right."
data "done"
'--------------------------end of help screen--------------------------------
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Initialize.Parameters:
4000'
'Get DOS command line parameters:
CMD$=command$
'if /E present, use EMS memory:
IF INSTR(CMD$, "/E") or INSTR(CMD$, "/e") THEN TSR = -1
'if /S present, use disk swapping:
s= INSTR(CMD$, "/S"): if s=0 then s=INSTR(CMD$, "/s")
IF s>0 THEN
TSR = -1
operation=7
DIR$=MID$(CMD$, s+2)
kshift=varptr(DIR$)
CALL StayRes(operation, kscan, kshift, ecode)
IF ecode=3 then
PRINT "Must use DOS 3 for disk swapping.";
x$="": WHILE x$="": x$=INKEY$: WEND
END
END IF
IF ecode THEN
PRINT "Can't use " dir$;
x$="": WHILE x$="": x$=INKEY$: WEND
END
END IF
END IF
'Variables for ForeGround, HighLight & BackGround colors:
f=INSTR(CMD$, "/FG"): if f=0 then f=INSTR(CMD$, "/fg")
b=INSTR(CMD$, "/BG"): if b=0 then b=INSTR(CMD$, "/bg")
h=INSTR(CMD$, "/HL"): if h=0 then h=INSTR(CMD$, "/hl")
IF f>0 THEN FG=VAL(MID$(CMD$,f+3,2)) ELSE FG=7
IF b>0 THEN BG=VAL(MID$(CMD$,b+3,2)) ELSE BG=0
IF h>0 THEN HL=VAL(MID$(CMD$,h+3,2)) ELSE HL=15
'These tones are used to indicate change in -Lock status, etc:
IF INSTR(CMD$, "/q")=0 AND INSTR(CMD$, "/Q")=0 THEN
Lock.Tone=400
Duration!= .4
EEK=4000
EEK!=.04
END IF
''''''''''''''''''''end of command line processing''''''''''''''''''
Char.Num=1 'points to cursor position within edit area.
Line.Num=1 'points to cursor row within edit area.
Last.Line=1 'last line with text in it.
First.View.Line=1 'line number of top line in edit area.
Last.View.Line=Last.Row-First.Row+1 'line number of last line in edit area.
Num.View.Lines = Last.View.Line 'max lines allowed in edit area.
Max.Text.Len=Last.Col-First.Col+1 'max line length.
First.Row=First.Row-1 'for easier computations.
Yes= -1
No = 0
Wrap.On = Yes 'word wrap may be toggled, but starts turned on.
Indent.On = Yes 'turn on automatic Indents.
FOR x=1 TO Max.Lines
Text$(x)=SPACE$(Max.Text.Len)
NEXT
WIDTH 80
DEF SEG=0
COLR= (PEEK(&H410) AND &H30)<>&H30
DEF SEG
IF COLR THEN_ 'cursor shape definition:
CU1=4:_
CU2=7_
ELSE CU1=11:_
CU2=13
Delimiter$ = " ,.-;:=+(<#*{['/" + CHR$(34)
'variables for displaying -Lock status:
Locks$(0)=STRING$(7," ")
Locks$(1)=STRING$(4," ")+"NUM"
Locks$(2)="CAP"+STRING$(4," ")
Locks$(3)="CAP"+CHR$(32)+"NUM"
On.Off$(0)="ON "
On.Off$(1)="OFF"
Entr$=CHR$(13)
Bksp$=CHR$(8)
Esc$=CHR$(27)
Entr.symbol$=" "+CHR$(17)+STRING$(2,196)+CHR$(217)+" " 'not used this pgm.
'key scan codes:
LF.Cursor=75
RT.Cursor=77
Ctrl.LF=115
Ctrl.RT=116
UP.Cursor=72
DN.Cursor=80
PG.UP=73
PG.DN=81
Ctrl.PgUp=132
Ctrl.PgDn=118
Home=71
Ctrl.Home=119
End.Key=79
Ctrl.End=117
Ins.Key=82
Del.Key=83
ESC=27
Alt.B=48 'define block of lines
Alt.C=46 'clear all lines
Alt.D=32 'delete line at cursor
Alt.E=18 'erase block
Alt.F=33 'find text
Alt.G=34 'get next file section
Alt.H=35 'display help
Alt.I=23 'toggle auto-indent
Alt.K=37 'toggle auto-kap
Alt.L=38 '
Alt.M=50 'set right Margin
Alt.N=49 'new file
Alt.P=25 'paste block
Alt.R=19 'reform paragraph
Alt.S=31 'save file
Alt.U=22 'unmark block
Alt.W=17 'toggle word wrap
Alt.X=45 'exit
'attribute codes FOR the asm subroutine:
FG.BG=FG+(BG AND 7)*16 'normal foreground-background
HL.BG=HL+(BG AND 7)*16 'highlighted foreground-normal background 'not used
BG.FG=BG+(FG AND 7)*16 'inverse video 'not used in this program
Attrib=FG.BG 'Attribute is normally set to the foreground/background colors.
'The Attrib variable is used in the quick-print subroutine.
RESTORE Qprint.data
DEF SEG
FOR J=0 TO 106
READ H$
C$="&H"+H$
X=VAL(C$)
POKE (VARPTR(QPrint.CODE(0))+J),X
NEXT
Qprint.data:
'-----------
DATA 55, 8B,EC, 8B,5E,08, 8B,3F, 4F, 8B,5E,0A, 8B,07, 48
DATA 8B,5E,0C, B5,00, 8A,0F, 80,F9,00, 74,37, 8B,77,02, BB,40,00
DATA 8E,C3, 26, F7,26,4A,00, 03,F8, D1,E7, 26, 8B,16,63,00
DATA 83,C2,06, B8,00,B8, 26, 8B,1E,10,00, 81,E3,30,00
DATA 83,FB,30, 75,03, B8,00,B0, 8B,5E,06, 8A,3F, 8E,C0
DATA E8,04,00, 5D, CA,08,00, AC, 8A,D8, EC, A8,01, 75,FB, FA, EC
DATA A8,01, 74,FB, 8B,C3, AB, FB, E2,EC, C3
LOCATE ,,1
IF TSR THEN 'This implements MicroHelp's code to make editor resident.
Operation=0 ' can be purchased from MicroHelp.
Kshift=12 ' \___Ctrl-Alt-E is the hot key. See StayRes manual to change.
Kscan=18 ' /
Ecode=100
CALL StayRes(Operation, Kscan, Kshift, Ecode)
IF Ecode > 0 THEN PRINT "StayRes Error" Ecode: stop
END IF
RETURN
'end of Initialize.Parameters
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
5000
Load.File:
'have to have a line number for error trapping
GOSUB Get.filename
IF f$<>"" THEN GOSUB Load.it
GOSUB Prnt.Lines
RETURN
Get.filename:
'------------
COLOR FG,BG
CLS : f$="": New.Fi$="" : keep.going = yes
WHILE keep.going
IF f$<>"" THEN FILES f$
PRINT
PRINT "Enter DIR or DIR A:FILENAME or DIR B:*.DOC, etc, for directories."
PRINT "Just press ENTER to edit a new file or a file already in memory."
IF NOT TSR THEN PRINT "Enter QUIT to exit the program."
PRINT: PRINT "Name of file to edit: "; : col=pos(0)
GOSUB Get.input
f$=LEFT$(text$(0), Text.Len(0))
PRINT: PRINT
IF NOT TSR THEN IF f$="quit" OR f$="QUIT" THEN CLS : END
IF LEFT$(f$+" ",3)="DIR" OR LEFT$(f$+" ",3)="dir" THEN
IF LEN(f$) < 5 THEN
f$="*.*"
ELSE f$=mid$(f$,5)
END IF
ELSE keep.going = no
END IF
WEND
Line.Num=1
RETURN
Load.it:
'-------
IF Last.Line > 0 THEN GOSUB Clear.mem
Fi$=f$
OPEN Fi$ FOR INPUT AS #1
PRINT: PRINT: PRINT "Loading " Fi$: PRINT
Next.section=0
Trunc$="0"
Read.in.text:
Start.section = Next.section
WHILE NOT EOF(1) AND Next.section = Start.section
Last.Line = Last.Line + 1
LINE INPUT #1, x$
MID$(Text$(Last.Line),1)=x$
Line.Num=Last.Line
GOSUB Find.Text.Len
IF LEN(x$) > Max.Text.Len THEN IF Trunc$<>"1" THEN GOSUB Long.line
IF Last.Line => Max.Lines THEN GOSUB Big.file
WEND
CLOSE: Line.Num=1: Char.Num=1
IF Next.section > 0 THEN_
IF Start.Section = Next.section_
THEN End.of.big.file = yes:_
Next.section=Last.line+1_
ELSE End.of.big.file = no
RETURN
Big.file:
'--------
IF Next.section = 0 THEN
PRINT "File exceeds the maximum of" Max.Lines " lines (per section)."
PRINT "At the present, MyEd allows only limited editing of longer files."
PRINT "You can edit one piece of the file at a time, but not go back without
PRINT "restarting the file over (ie: Alt-X). A limit of 50 new lines can be
PRINT "added to each section without starting over or deleting more lines."
PRINT "The process of saving 500 lines and loading the next 500 lines is"
PRINT "pretty slow, but it does make it possible to edit any size file."
PRINT "To Get the next section while editing, press Alt-G."
PRINT: PRINT "Make sure that enough disk space is available and"
PRINT "enter drive and filename to use for new file: "; : col=POS(0)
GOSUB get.input: PRINT
New.Fi$=LEFT$(text$(0),Text.Len(0))
OPEN New.Fi$ FOR OUTPUT AS #2: CLOSE #2 'make sure filename is ok.
END IF
Next.section = Start.section + Max.Lines-50
FOR x=Max.Lines-49 to Max.Lines
Text$(x)=SPACE$(Max.Text.Len)
Text.Len(x)=0
NEXT
Last.Line=450
RETURN
Long.line:
'---------
WHILE INSTR("123",Trunc$)=0
PRINT left$(x$, Max.Text.Len);
COLOR BG,FG: PRINT mid$(x$, Max.Text.Len+1): COLOR FG,BG
PRINT: PRINT "Line exceeds maximum line length of"Max.Text.Len".
PRINT "1-Truncate 2-Wrap 3-Abort: ";
Trunc$="": WHILE Trunc$="": Trunc$=INKEY$: WEND: PRINT
PRINT "Keep asking each time? (y/n): ";
ka$="": WHILE ka$="": ka$=INKEY$: WEND: PRINT
WEND
IF Trunc$="3" THEN RETURN 5000
IF Trunc$="2" AND Last.Line < Max.Lines THEN
Last.Line = Last.Line +1
MID$(Text$(Last.Line),1) = MID$(x$, Max.Text.Len+1)
Line.Num=Last.Line
GOSUB Find.Text.Len
END IF
IF INSTR("Nn", ka$)=0 THEN Trunc$="0"
RETURN
'''''''''''''''''''''''''''''end of Load.File''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
6000' Save file:
Save.exit:
IF W$=Esc$ THEN_
IF NOT TSR_
THEN CLS: END_
ELSE GOTO Exit.to.DOS
LOCATE Msg.Line,25: PRINT SPACE$(40);
LOCATE Msg.Line,25: ans$=""
IF New.Fi$<>"" THEN
COLOR HL+15: PRINT " Saving " New.fi$;
GOTO Save.it
END IF
IF Fi$ <> "" THEN
COLOR HL: PRINT "Save file as " Fi$ " (y/n) ";: COLOR FG
ans$="": WHILE ans$="": ans$=INKEY$: WEND
LOCATE Msg.Line,25: PRINT SPACE$(40);
END IF
IF ans$ <> "y" AND ans$ <> "Y" THEN
LOCATE Msg.Line,25: COLOR HL
PRINT "Enter new filename: ";: COLOR FG : col=POS(0)
GOSUB Get.input
Fi$=LEFT$(Text$(0), Text.Len(0))
IF Fi$="" THEN
LOCATE Msg.Line,25: PRINT SPACE$(40);
LOCATE Msg.Line,25: COLOR HL
PRINT "Quit without saving (y/n)";
COLOR FG
abort$="": WHILE abort$="": abort$=INKEY$: WEND
IF abort$<>"Y" AND abort$<>"y" THEN
LOCATE Msg.Line,25: PRINT SPACE$(40);:
KY=0
RETURN
ELSE GOTO Exit.to.DOS
END IF
END IF
END IF
LOCATE Msg.Line,25: PRINT SPACE$(40);
LOCATE Msg.Line,25: COLOR HL: PRINT " Saving " Fi$;
save.it:
IF New.Fi$<>""_
THEN OPEN New.Fi$ FOR APPEND AS #1_
ELSE OPEN Fi$ FOR OUTPUT AS #1
FOR x=1 TO Last.Line
PRINT #1, LEFT$(Text$(x), Text.Len(x))
NEXT
CLOSE
IF KY=Alt.G THEN RETURN
IF New.Fi$<>"" THEN_
IF NOT End.of.big.file THEN GOSUB Close.big.file
Exit.to.DOS:
'-----------
LOCATE Msg.Line,25: PRINT SPACE$(40);
IF TSR THEN CALL StayRes(Operation, Kscan, Kshift, Ecode):_
GOSUB Prnt.Lines
IF NOT TSR THEN END
RETURN
Close.big.file:
'--------------
6500'
OPEN Fi$ FOR INPUT AS #1
FOR x=1 TO Next.section : LINE INPUT #1, x$: NEXT
OPEN New.Fi$ FOR APPEND AS #2
WHILE NOT EOF(1)
LINE INPUT #1, A$
PRINT #2, A$
WEND
CLOSE
RETURN
Err.Trap:
'========
6600 CLOSE
LOCATE Msg.Line,25:PRINT SPACE$(45);:LOCATE Msg.Line,25
COLOR HL
IF ERR=64 THEN
PRINT "Bad file name";
ELSEIF ERR=61 THEN
PRINT "Disk full";
ELSEIF ERR=72 THEN
PRINT "Disk media error";
ELSEIF ERR=71 THEN
PRINT "Drive not ready";
ELSEIF ERR=53 THEN
PRINT "File not found";
ELSEIF ERR=7 OR ERR=14 THEN
PRINT "Out of memory";
ELSEIF ERR=76 THEN
PRINT "Path not found";
ELSEIF ERR=70 THEN
PRINT "Disk/file write-protected";
ELSE PRINT "Error number" ERR; "in line number" ERL;
END IF
COLOR FG: xe$=""
WHILE xe$="": xe$=INKEY$: WEND
IF ERL=1801 THEN RESUME 1801
IF ERL=5000 THEN f$="": RESUME 5000
IF ERL=6000 THEN RESUME 6000
IF ERL=6500 THEN RESUME 6500
GOTO Exit.to.DOS